﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Soft.Data
{

    /// <summary>
    /// 封装调用参数 （InvokeParam）
    /// </summary>
    [Serializable]
    public sealed class InvokeParameItem : IEquatable<InvokeParameItem>
    {

        /// <summary>
        /// 是否是相等
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool Equals(InvokeParameItem other)
        {
            return other != null && this.Name.Equals(other.Name);
        }


        /// <summary>
        /// 参数名称
        /// </summary>
        public string Name;


        /// <summary>
        /// 参数类型
        /// </summary>
        public string ValueType;


        /// <summary>
        /// 参数值
        /// </summary>
        public string Value;


        /// <summary>
        /// 默认构造函数
        /// </summary>
        public InvokeParameItem()
        {
            this.Name = string.Empty;
            this.ValueType =JsonConvertHelper.JsonNull;
            this.Value = JsonConvertHelper.JsonNull;
        }


        /// <summary>
        /// 有参构造函数
        /// </summary>
        /// <param name="name">参数名</param>
        /// <param name="value">参数值</param>
        public InvokeParameItem(string name, object value) : this()
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }
            this.Name = name;
            if (value != null)
            {
                this.ValueType = value.GetType().AssemblyQualifiedName;
                this.Value = JsonConvertHelper.ToJson(value);
            }
        }


    }
}
